//
//  JKHomeViewController.swift
//  afanti
//
//  Created by albert on 16/4/15.
//  Copyright © 2016年 albert. All rights reserved.
//

import UIKit

class JKHomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.navigationItem.title = "主页"
        
        let imageView = UIImageView()
        imageView.backgroundColor = UIColor.redColor()
        imageView.image = UIImage(named: "home_bg")
        imageView.frame = CGRect(x: 0, y: 44, width: view.bounds.size.width, height: view.bounds.size.height)
        view.addSubview(imageView)
        
        let button = UIButton(type: UIButtonType.Custom)
        button.bounds = CGRect(x: 0, y: 0, width: 150, height: 179)
        button.center = view.center
        button.setImage(UIImage(named: "aft_home_camera"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "aft_home_camera_press"), forState: UIControlState.Highlighted)
        button.addTarget(self, action: "takePicture", forControlEvents: UIControlEvents.TouchUpInside)
        view.addSubview(button)
    }
    
    /** 点击拍照 */
    func takePicture(){
        let imagePicker = UIImagePickerController()
        
        imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
        imagePicker.allowsEditing = true
        
        imagePicker.delegate = self
        
        
        self.presentViewController(imagePicker, animated: true, completion: nil)
    }
}

extension JKHomeViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate{
    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
//        let image = info[UIImagePickerControllerOriginalImage]
        
        self .dismissViewControllerAnimated(true, completion: nil)
    }
}